package xs.szw.common.exception;

import lombok.Getter;
import org.slf4j.helpers.MessageFormatter;
import xs.szw.common.result.ResultCode;

/**
 * @program: xs_oa
 * @description: 自定义业务异常  -> 用于业务逻辑校验
 * @author: Songzw
 * @create: 2025-02-16 14:47
 **/
@Getter
public class BusinessException extends RuntimeException {
    /**
     *  错误码
     */
    private String code;
    /**
     * 错误信息
     */
    private String message;

    public BusinessException(String code,String message){
        super(message);
        this.code = code;
        this.message = message;
    }

    public BusinessException(ResultCode resultCode){
        super(resultCode.getMessage());
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    public BusinessException(Throwable cause) {
        super(cause);
    }

    public BusinessException(String message, Object... args) {
        super(formatMessage(message, args));
    }

    private static String formatMessage(String message, Object... args) {
        return MessageFormatter.arrayFormat(message, args).getMessage();
    }
}

